var RepairTableInfo = function (repair) {
  BaseModel.call(this);
  var self = this;

  var fn = {
    initData: function (repair) {
      var fields = ['machineModel', 'machineSerialNo', 'custCompany', 'custName', 'custPhone', 'workBrokenDescription', 'errorMsg',
        'errorCode', 'workName', 'status', 'remark', 'custBrokenPart', 'custBrokenDescription', 'workManagerName', 'workBrokenPart',
        'workBrokenSolveWay', 'custOpinion', 'workCompleteLocation'
      ];
      self.setDataFromObj(repair, fields);

      var custPhoto = repair.custPhoto;
      if (SysUtil.isEmpty(custPhoto)) {
        self.custPhoto = [];
      } else {
        self.custPhoto = custPhoto.split(',');
      }

      var custEvaluation = repair.custEvaluation;
      var evaluationCount = Number(custEvaluation);
      if (!isNaN(evaluationCount)) {
        custEvaluation = evaluationCount + '星评价';
      }
      self.custEvaluation = custEvaluation;

      var createTime = repair.createTime;
      createTime = moment(createTime).valueOf();
      self.createTime = createTime;

      self.custPayText = this.getCustPayText(repair);
      self.assignDifferTime = this.getDifferTime(createTime, repair.assignTime);
      self.completeDifferTime = this.getDifferTime(repair.assignTime, repair.workCompleteTime);
    },

    getCustPayText: function (repair) {
      if (repair.status <= 1) {
        return '';
      }

      var balancePrice = repair.balancePrice;
      if (balancePrice === 0) {
        return '不收费已结算';
      }

      var custPay = repair.custPay;
      custPay = Number(custPay);
      var custPayText = custPay === 1 ? '收费' : '不收费';
      if (balancePrice === null) {
        var str = custPay === 1 ? '待结算' : '已结算';
        custPayText += str;
      } else {
        if (custPay === 1) {
          custPayText += '已结算';
        }
      }
      return custPayText;
    },

    getDifferTime: function (data1, data2) {
      if (SysUtil.isEmpty(data1) || SysUtil.isEmpty(data2)) {
        return '';
      }

      if (typeof data1 === 'string') {
        data1 = moment(data1).valueOf();
      }

      if (typeof data2 === 'string') {
        data2 = moment(data2).valueOf();
      }

      var time = moment(data2).diff(data1);
      time = moment.duration(time);

      var differTime = '';
      var day = time.asDays();
      day = Math.floor(day);
      if (day > 0) {
        differTime += `${day}天`;
      }

      var hour = time.hours();
      if (hour > 0) {
        differTime += `${hour}小时`;
      }

      var minute = time.minutes();
      if (minute > 0) {
        differTime += `${minute}分钟`;
      }

      if (differTime === '') {
        var second = time.seconds();
        if (second > 0) {
          differTime += `${second}秒`;
        }
      }
      return differTime;
    }
  };

  fn.initData(repair);
};
